package com.itheima_12;

public class Student implements Comparable<Student>{
    private String name;
    private int Chines;
    private int math;
    private int English;

    public Student() {
    }

    public Student(String name, int chines, int math, int english) {
        this.name = name;
        Chines = chines;
        this.math = math;
        English = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChines() {
        return Chines;
    }

    public void setChines(int chines) {
        Chines = chines;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return English;
    }

    public void setEnglish(int english) {
        English = english;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (Chines != student.Chines) return false;
        if (math != student.math) return false;
        if (English != student.English) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + Chines;
        result = 31 * result + math;
        result = 31 * result + English;
        return result;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", Chines=" + Chines +
                ", math=" + math +
                ", English=" + English +
                '}';
    }
public int sum(){
        return Chines+math+English;
}

    @Override
    public int compareTo(Student o) {

        int result=this.sum()-o.sum();
        result=result==0? this.Chines-o.Chines:result;
        result=result==0? this.math-o.math:result;
        result=result==0? this.English-o.English:result;
        result=result==0?this.getName().compareTo(o.getName()):result;
        if(result==0){
            result=1;
        }
        return result;
    }
}
